package com.ruoyi.web.controller.sr;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SrRecord;
import com.ruoyi.system.service.ISrRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学习记录排行榜Controller
 * 
 * @author ruoyi
 * @date 2023-04-04
 */
@RestController
@RequestMapping("/system/record")
public class SystemRecordController extends BaseController
{
    @Autowired
    private ISrRecordService srRecordService;

    /**
     * 查询学习记录排行榜列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(SrRecord srRecord)
    {
        startPage();
        List<SrRecord> list = srRecordService.selectSrRecordList(srRecord);
        return getDataTable(list);
    }

    /**
     * 导出学习记录排行榜列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:export')")
    @Log(title = "学习记录排行榜", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SrRecord srRecord)
    {
        List<SrRecord> list = srRecordService.selectSrRecordList(srRecord);
        ExcelUtil<SrRecord> util = new ExcelUtil<SrRecord>(SrRecord.class);
        util.exportExcel(response, list, "学习记录排行榜数据");
    }

    /**
     * 获取学习记录排行榜详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(srRecordService.selectSrRecordById(id));
    }

    /**
     * 新增学习记录排行榜
     */
    @PreAuthorize("@ss.hasPermi('system:record:add')")
    @Log(title = "学习记录排行榜", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SrRecord srRecord)
    {
        return toAjax(srRecordService.insertSrRecord(srRecord));
    }

    /**
     * 修改学习记录排行榜
     */
    @PreAuthorize("@ss.hasPermi('system:record:edit')")
    @Log(title = "学习记录排行榜", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SrRecord srRecord)
    {
        return toAjax(srRecordService.updateSrRecord(srRecord));
    }

    /**
     * 删除学习记录排行榜
     */
    @PreAuthorize("@ss.hasPermi('system:record:remove')")
    @Log(title = "学习记录排行榜", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(srRecordService.deleteSrRecordByIds(ids));
    }
}
